//
//  BaseModel.m
//  UI19_视图切换
//
//  Created by qing on 16/3/8.
//  Copyright © 2016年 qing. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel
//初始化
- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        //KVC赋值
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
//便利构造器
+ (instancetype)modelWithDic:(NSDictionary *)dic {
    id m = [[[self class] alloc] initWithDic:dic];
    return m;
}

//转化
+ (NSMutableArray *)transformWithArray:(NSArray *)arr {
    //创建空数组
    NSMutableArray *mArr = [NSMutableArray array];
    //遍历传入参数
    for (NSDictionary *dic in arr) {
        //创建对象
        id m = [[self class] modelWithDic:dic];
        //添加到数组中
        [mArr addObject:m];
    }
    return mArr;
}

//KVC 赋值容错方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

@end
